package br.com.imob.dao;

import br.com.imob.modelo.Face;

import java.util.List;

/** @user Gilton Nascimento
 *  @since 11:31:35 31/01/2011 2011
 *  @version 
 */

public class FaceDao extends GenericDao {
	
	public FaceDao() {  }
	
	public Integer adicionarFace(Face face) {
		saveOrUpdatePojo(face);
		return face.getFaceId();
	}
	
	public void removerFace(Face face) {
		removerPojo(face);
	}

	/* Precisa definir o ID */
	public void atualizarFace(Face recupera) {
		saveOrUpdatePojo(recupera);
	}
	
	/**
	 * Editar um Face
	 * @param String oldFace
	 * @param String newFace
	 */
	public void atualizarFace(String oldFace, String newFace ) {
		if ( ( !"".equals(oldFace) && oldFace != null )
			&& ( !"".equals(newFace) && newFace != null ) ) 
			atualizarFace( getFaceQNamed(oldFace), new Face(newFace) );
	}
	
	/* Precisa definir qual atribuito sera a chave a identificar 
	 * a tupla a ser alterada */
	public void atualizarFace(Face recuperar, Face alterar) {
		recuperar = retriveFace(recuperar);
		
		if(alterar.getFace() != null)
			recuperar.setFace(alterar.getFace());
		
		saveOrUpdatePojo(recuperar);
	}
	
//	Artificio para Recuperar a Tupla de Face
	protected Face retriveFace(Face recuperar) {
		if(recuperar.getFaceId() == null)
			return getFaceQNamed(recuperar.getFace());
		else 
			return getFace(recuperar.getFaceId());
	}
	
	
//	Consultas
	public Face getFace(Integer key) {
		return getPojoByID(Face.class, key);
	}
	public Face getFaceByQuery(String query, Object...params) {
		return getPojoByQry(query, params);
	}
	public Face getFaceQNamed(String fltrFace) {
		return getPojoByQNamed("Face.findByFace", fltrFace);
	}
	
	public List<Face> getFaces() {
		return (List<Face>) getALL(Face.class);
	}
	public List<Face> getFacesQNamedPRX(String fltrFace) {
		return getListByQNamedPRX("Face.findLikeByFace", fltrFace);
	}
	public List<Face> getFacesByQuery(String query, Object...params) {
		return getListByQry(query, params);
	}
}